home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / faxd / Class1.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  7KB  |  160 lines

  1. /*    $Header: /usr/people/sam/fax/faxd/RCS/Class1.h,v 1.36 1994/04/07 21:53:22 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #ifndef _CLASS1_
  26. #define    _CLASS1_
  27. /*
  28.  * EIA/TIA-578 (Class 1) Modem Driver.
  29.  */
  30. #include "FaxModem.h"
  31.  
  32. class HDLCFrame;
  33.  
  34. /*
  35.  * Class 1 modem capability (for sending/receiving).
  36.  */
  37. typedef struct {
  38.     u_char    value;    // Class 1 parameter value (e.g for +FRM)
  39.     u_char    br;    // Class 2 bit rate parameter
  40.     u_short    sr;    // T.30 DCS signalling rate
  41.     u_char    mod;    // modulation technique
  42.     fxBool    ok;    // true if modem is capable
  43. } Class1Cap;
  44. #define    HasShortTraining(c) \
  45.     ((c)->mod == V17 && ((c)->value & 1) && (c)[1].ok)
  46.  
  47. class Class1Modem : public FaxModem {
  48. protected:
  49.     u_int    dis;            // current remote DIS
  50.     Class2Params params;        // current params during send
  51.     long    group3opts;        // for writing received TIFF
  52.     const u_char* frameRev;        // HDLC frame bit reversal table
  53.     fxStr    lid;            // encoded local id string
  54.     Class1Cap    xmitCaps[15];        // modem send capabilities
  55.     Class1Cap    recvCaps[15];        // modem recv capabilities
  56.     const Class1Cap* curcap;        // capabilities being used
  57.     u_int    discap;            // DIS signalling rate capabilities
  58.     fxBool    prevPage;        // a previous page was received
  59.     fxBool    pageGood;        // quality of last page received
  60.  
  61.     static const u_int modemPFMCodes[8];// map T.30 FCF to Class 2 PFM
  62.     static const u_int modemPPMCodes[8];// map T.30 FCF to Class 2 PPM
  63.     static const Class1Cap basicCaps[15];
  64.  
  65.     enum {            // modulation techniques
  66.     V21   = 0,        // v.21, ch 2 300 bits/sec
  67.     V27FB = 1,        // v.27ter fallback mode
  68.     V27   = 2,        // v.27ter, 4800, 2400
  69.     V29   = 3,        // v.29, 9600, 7200
  70.     V17   = 4,        // v.17, 14400, 12000, 9600, 7200
  71.     V33   = 5,        // v.33, 14400, 12000, 9600, 7200
  72.     };
  73.     static const char* modulationNames[6];
  74.  
  75. // modem setup stuff
  76.     virtual fxBool setupModem();
  77.     virtual fxBool setupClass1Parameters();
  78. // transmission support
  79.     fxBool    sendPrologue(u_int dcs, const fxStr& tsi);
  80.     fxBool    dropToNextBR(Class2Params&);
  81.     fxBool    raiseToNextBR(Class2Params&);
  82.     fxBool    sendTraining(Class2Params&, int, fxStr& emsg);
  83.     fxBool    sendTCF(const Class2Params&, u_int ms);
  84.     fxBool    sendPage(TIFF* tif, const Class2Params&, fxStr& emsg);
  85.     fxBool    sendPageData(u_char* data, u_int cc, const u_char* bitrev);
  86.     fxBool    sendRTC(fxBool is2D);
  87.     fxBool    sendPPM(u_int ppm, HDLCFrame& mcf, fxStr& emsg);
  88. // reception support
  89.     const AnswerMsg* findAnswer(const char*);
  90.     fxBool    recvIdentification(u_int f1, const fxStr& id,
  91.             u_int f2, u_int dics, u_int timer, fxStr& emsg);
  92.     fxBool    recvDCSFrames(HDLCFrame& frame);
  93.     fxBool    recvTraining();
  94.     fxBool    recvPPM(int& ppm, fxStr& emsg);
  95.     fxBool    recvPhaseC(TIFF*, fxStr& emsg);
  96.     void    recvData(TIFF*, u_char* buf, int n);
  97.     void    processDCSFrame(const HDLCFrame& frame);
  98. // miscellaneous
  99.     enum {            // Class 1-specific AT responses
  100.     AT_FCERROR    = 100,    // "+FCERROR"
  101.     };
  102.     virtual ATResponse atResponse(char* buf, long ms = 30*1000);
  103.     virtual fxBool waitFor(ATResponse wanted, long ms = 30*1000);
  104.     void    encodeTSI(fxStr& binary, const fxStr& ascii);
  105.     void    decodeTSI(fxStr& ascii, const HDLCFrame& binary);
  106.     const Class1Cap* findSRCapability(u_short sr, const Class1Cap[]);
  107.     const Class1Cap* findBRCapability(u_short br, const Class1Cap[]);
  108. // class 1 HDLC frame support
  109.     fxBool    transmitFrame(u_char fcf, fxBool lastFrame = TRUE);
  110.     fxBool    transmitFrame(u_char fcf, u_int, fxBool lastFrame = TRUE);
  111.     fxBool    transmitFrame(u_char fcf, const fxStr&, fxBool lastFrame=TRUE);
  112.     fxBool    transmitData(int br, u_char* data, u_int cc,
  113.             const u_char* bitrev, fxBool eod);
  114.     fxBool    sendFrame(u_char fcf, fxBool lastFrame = TRUE);
  115.     fxBool    sendFrame(u_char fcf, u_int, fxBool lastFrame = TRUE);
  116.     fxBool    sendFrame(u_char fcf, const fxStr&, fxBool lastFrame = TRUE);
  117.     fxBool    sendRawFrame(HDLCFrame& frame);
  118.     fxBool    sendClass1Data(const u_char* data, u_int cc,
  119.             const u_char* bitrev, fxBool eod);
  120.     fxBool    recvFrame(HDLCFrame& frame, long ms = 10*1000);
  121.     fxBool    recvTCF(int br, HDLCFrame&, const u_char* bitrev, long ms);
  122.     fxBool    recvRawFrame(HDLCFrame& frame);
  123.     void    abortReceive();
  124.     void    traceHDLCFrame(const char* direction, const HDLCFrame& frame);
  125. // class 1 command support routines
  126.     fxBool    class1Cmd(const char* cmd, ATResponse r);
  127.     fxBool    class1Cmd(const char* cmd, int a0, ATResponse r);
  128.     fxBool    class1Query(const char* what, Class1Cap caps[]);
  129.     fxBool    parseQuery(const char*, Class1Cap caps[]);
  130. public:
  131.     Class1Modem(FaxServer&, const ModemConfig&);
  132.     virtual ~Class1Modem();
  133.  
  134. // send support
  135.     CallStatus    dial(const char* number);
  136.     CallStatus    dialResponse();
  137.     fxBool    getPrologue(Class2Params&, u_int& nsf, fxStr&, fxBool& hasDoc);
  138.     void    sendBegin();
  139.     void    sendSetupPhaseB();
  140.     fxBool    sendPhaseB(TIFF* tif, Class2Params&, FaxMachineInfo&,
  141.             fxStr& pph, fxStr& emsg);
  142.     void    sendEnd();
  143.  
  144. // receive support
  145.     CallType    answerCall(AnswerType, fxStr& emsg);
  146.     u_int    modemDIS() const;
  147.     fxBool    recvBegin(fxStr& emsg);
  148.     fxBool    recvPage(TIFF*, int& ppm, fxStr& emsg);
  149.     fxBool    recvEnd(fxStr& emsg);
  150.  
  151. // polling support
  152.     fxBool    requestToPoll();
  153.     fxBool    pollBegin(const fxStr& pollID, fxStr& emsg);
  154.  
  155. // miscellaneous
  156.     fxBool    reset(long ms = 5*1000);    // reset modem
  157.     void    setLID(const fxStr& number);    // set local id string
  158. };
  159. #endif /* _CLASS1_ */
  160.